#ifndef HIGHLIGHTTEXTVIEWER_H
#define HIGHLIGHTTEXTVIEWER_H

#include <QTextBrowser>
#include <QTextBlock>
#include <qtextcursor.h>
#include <QMouseEvent>
#include <qaction.h>

#include <qtimer.h>

/**
 * @brief The HighLightTextViewer class customize the behavoiur
 * of \a QTextBrowser, adding the 'script automation' behavoiur by
 * implementing many functions from \a IF_ScriptViewerInterface.
 * This class can be used by concrete children of \a IF_ScriptViewerInterface
 * to implement such interface.
 */

class HighLightTextViewer : public QTextBrowser
{
   Q_OBJECT
public:
   explicit HighLightTextViewer(QWidget *parent = 0);

public slots:
   void resetStyle();

public:
   void onActivateNextBlock();
   int getActiveBlockLength() const;
   void getScriptContent(QString &content) const ;
   void setScriptContent(const QString &content);
   void setEditMode(bool);

public:
   virtual void setHtml( const QString & text );

signals:
   void filteredMouseMoveEvent( const QPoint &);

protected:
   // reimplemented
   virtual void mouseMoveEvent(QMouseEvent *);
   void resizeEvent(QResizeEvent *event);
   void mouseDoubleClickEvent(QMouseEvent *);

public:
   void highlightActiveBlock();
   void setCurrentBlock(const QTextBlock &block);
   void activeBlockClearHighlight();
   void onImageClicked(QTextCursor &);
   void activateBlock( const QTextBlock & block);
   void scrollToActiveBlock();

   QTextBlock calculateNextBlock();

private slots:
   void onFilteredMoveTimerExpired();

private:
   QTextCursor  *m_cursor;
   QTextBlock   m_currentBlock;
   bool         m_editMode;

   QColor       m_textHighLight;
   QColor       m_bgHighLight;

   /** this timer expires when mouse is moved and then
    *  stopped for a given time
    */
   QTimer  m_filteredMoveTimer;
};

#endif // HIGHLIGHTTEXTVIEWER_H
